# @Time    : 2018/5/30 17:46
# @Author  : Jame
from lib import common
from interface import common_interface,teacher_interface

teacher_info={
    'name':None,
    'role':'teacher'
}


def teacher_login():
    print('老师登陆>>>')
    while True:
        name = input('请输入用户名:').strip()
        if teacher_info['name'] == name:
            print('%s 已登陆，请勿重复重登录...'%teacher_info['name'])
            break

        password = input('请输入密码:').strip()
        flag,msg = common_interface.login(name,password,teacher_info['role'])
        if flag:
            print(msg)
            teacher_info['name'] = name
            break
        else:
            print(msg)



@common.auth_type(teacher_info['role'])
def teacher_check_course():
    print('%s 老师教授的课程如下:'%teacher_info['name'])
    flag,msg=teacher_interface.teacher_check_course_interface(teacher_info['name'])
    if flag: #不为空则打印课程
        for n,v in enumerate(msg):
            print('[%s] :   %s'%(n,v))

    else:
        print(msg)


@common.auth_type(teacher_info['role'])
def teacher_choose_course():
    while True:
        flag1,msg1 = common_interface.chose_course()
        if flag1:
            course=msg1
            flag2,msg2=teacher_interface.teacher_select_course_interface(teacher_info['name'],course)
            if flag2:
                print(msg2)
                break
            else:
                print(msg2)
        else:
            print(msg1)





@common.auth_type(teacher_info['role'])
def teacher_check_student():
    print('老师查看教授班级的学生:')
    flag,msg=teacher_interface.teacher_check_student_interface(teacher_info['name'])
    if flag:
        for n, v in enumerate(msg):
            print('[%s] : %s' % (n, v))
    else:
        print(msg)



@common.auth_type(teacher_info['role'])
def teacher_modify_score():
    #思路：先通过老师名称，获取老师对象，打印老师的教授的课程，选择课程后，
    flag,msg=teacher_interface.update_student_score(teacher_info['name'])
    if flag:
        print(msg)
    else:
        print(msg)





func_dic = {
    '1': teacher_login,
    '2': teacher_check_course,
    '3': teacher_choose_course,
    '4': teacher_check_student,
    '5': teacher_modify_score,

}

def teacher_view():
    while True:
        print('''
        1、登录
        2、查看教授课程
        3、选择教授课程
        4、查看课程下学生
        5、修改学生成绩 
        ''')
        choice = input('please choice (q 退出)>>:').strip()
        if choice == 'q': break
        if choice not in func_dic:
            print('您输入的不在范围内,请重新输入.')
            continue
        else:
            func_dic[choice]()